package h0805;

import java.util.Scanner;
import java.util.regex.Pattern;

/**
  * @description TODO
  * @author 不知名帅哥
  * @date 2024/8/5 9:31
  * @version 1.0
*/
public class NRadixSubtraction2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String b_sub = sc.next();
        String sub = sc.next();
        System.out.println(getResult(n, b_sub, sub));
    }

    private static String getResult(int n, String bSub, String sub) {
        if (n<2||n>35) return "-1";

        //判断是否合法
        if (!isValid(bSub,n)||!isValid(sub,n)) return "-1";

        //解析
        Long b_sub_val=Long.parseLong(bSub,n);
        Long sub_val=Long.parseLong(sub,n);

        String diff=Long.toString(Math.abs(b_sub_val-sub_val),n);
        String sign=b_sub_val>=sub_val?"0":"1";

        return sign+" "+diff;
    }

    private static boolean isValid(String s, int n) {
        //含有前导0只有0值本身合法
        if (s.startsWith("0")) return "0".equals(s);

        //被减数和减数只能包含0-9，a-z
        Pattern reg=Pattern.compile("[^a-z0-9]");
        if (reg.matcher(s).find()) return false;

        //长度最多100
        if (s.length()>100) return false;

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c>='0'&&c<='9'&&Integer.parseInt(c+"")>=n) return false;

            if (c>='a'&&c<='z'&&c-87>=n) return false;
        }
        return true;
    }
}
